<?php
##############################################
#
#   后台首页
# @ Time : 2017-1-1 - 下午7:37:36
# @ Author : JiangYongWei <1085562810@qq.com>
# @ Encoding : UTF-8 language : PHP
#
##############################################

namespace Admin\Controller;
use Admin\Model\MenuModel;
use Admin\Model\OrderModel;
use Admin\Model\UsersModel;
use Admin\Model\ActivityModel;

class IndexController extends AdminBaseController {
	
	/**
	 * 后台首页
	 */
    public function index(){
    	$menu_model = new MenuModel();
    	//获取菜单
    	$menu_data = $menu_model -> getMenuData();
    	$this -> assign('menu', $menu_data);
        $this -> display('index');
    }
    
    /**
     * 后台首页欢迎界面
     */
    public function welcome(){
        $this->assign('sys_info', self::get_sys_info());
        self::count_info();
    	$this->display('index_v3');
    }
    
    /**
      * 系统信息
      * @date 2017年8月8日 - 下午3:16:14
      * @author JiangYongWei
     */
    static function get_sys_info(){
        $sys_info['os']             = PHP_OS;
        $sys_info['zlib']           = function_exists('gzclose') ? 'YES' : 'NO';//zlib
        $sys_info['safe_mode']      = (boolean) ini_get('safe_mode') ? 'YES' : 'NO';//safe_mode = Off
        $sys_info['timezone']       = function_exists("date_default_timezone_get") ? date_default_timezone_get() : "no_timezone";
        $sys_info['curl']			= function_exists('curl_init') ? 'YES' : 'NO';
        $sys_info['web_server']     = $_SERVER['SERVER_SOFTWARE'];
        $sys_info['phpv']           = phpversion();
        $sys_info['ip'] 			= GetHostByName($_SERVER['SERVER_NAME']);
        $sys_info['fileupload']     = @ini_get('file_uploads') ? ini_get('upload_max_filesize') :'unknown';
        $sys_info['max_ex_time'] 	= @ini_get("max_execution_time").'s'; //脚本最大执行时间
        $sys_info['set_time_limit'] = function_exists("set_time_limit") ? true : false;
        $sys_info['domain'] 		= $_SERVER['HTTP_HOST'];
        $sys_info['memory_limit']   = ini_get('memory_limit');
        $sys_info['version']   	    = file_get_contents('./Application/Admin/Conf/version.txt');
        $mysqlinfo = M()->query("SELECT VERSION() as version");
        $sys_info['mysql_version']  = $mysqlinfo[0]['version'];
        if(function_exists("gd_info")){
            $gd = gd_info();
            $sys_info['gdinfo'] 	= $gd['GD Version'];
        }else {
            $sys_info['gdinfo'] 	= "未知";
        }
        return $sys_info;
    }
    
    /**
      * 统计
      * @date 2017年8月8日 - 下午3:21:22
      * @author JiangYongWei
     */
    public function count_info(){
        $today = strtotime("-1 day");
        $activity_model = new ActivityModel();
        $count[] = $activity_model->getActivityCount($today);
        
        $users_model = new UsersModel();
        $count[] = $users_model->getUserCount($today);
        
        $order_model = new OrderModel();
        $count[] = $order_model->getOrderCount($today);
        
        //总预约
        $count['all_make_users'] = M('make_users')->where('status!=3')->count();
        //新增预约
        $count['today_make_users'] = M('make_users')->where('status!=3 and create_time > '.$today)->count();
                 
        $this->assign('count', $count); 
        /* echo number_format("5000000")."<br>";
        echo number_format("5000000",2)."<br>";
        echo number_format("5000000",2,",","."); */
    }
}